<?php

namespace core\lib\drive\log;

use core\lib\Config;

class File
{
    private $path = '';

    public function __construct()
    {
        $conf = Config::get('OPTION', 'log');
        $this->path = $conf['PATH'];
    }

    public function log($msg, $file)
    {
        /**
         * 1.确定文件储存位置是否存在
         * 2.新建目录
         * 3.写入日志
         */
        //header("Content-type: text.txt/html; charset=utf-8");
        if (!is_dir($this->path)) {
            mkdir($this->path, '0755', true);
        }
        $logFile = $this->path . $file . '.log';
        $msg = is_array($msg) ? json_encode($msg, JSON_UNESCAPED_UNICODE) : $msg;
        $msg = date("Y-m-d H:i:s") . ' ' . $msg . PHP_EOL;
        return file_put_contents($logFile, $msg, FILE_APPEND);
    }
}